﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace JustinAngel.MindwaveSensor.WP8.Controls
{
    /// <summary>
    /// Displays current Mindwave eSense Attention alongside user instructions.  
    /// </summary>
    public class MindwaveAttentionProgressBar : MindwaveControl
    {
        public MindwaveAttentionProgressBar()
        {
            this.DefaultStyleKey = typeof (MindwaveAttentionProgressBar);
        }

        protected override void MindwaveSensorCurrentValueChanged(object sender, MindwaveReadingEventArgs e)
        {
            if (e.SensorReading.IsDataReliable)
            {
                CurrentReading = e.SensorReading;
            }

            base.MindwaveSensorCurrentValueChanged(sender, e);
        }

        protected override void UpdateVisualState()
        {
            if (!MindwaveSensor.IsDataValid)
                return; 

            if (MindwaveSensor.CurrentValue.eSenseAttention > 70)
                VisualStateManager.GoToState(this, "On", false);
            else
                VisualStateManager.GoToState(this, "Off", false);
        }

        #region public MindwaveReading CurrentReading
        /// <summary>
        /// Gets or sets the current reading used in this control. 
        /// </summary>
        public MindwaveReading CurrentReading
        {
            get { return GetValue(CurrentReadingProperty) as MindwaveReading; }
            set { SetValue(CurrentReadingProperty, value); }
        }

        /// <summary>
        /// Identifies the CurrentReading dependency property.
        /// </summary>
        public static readonly System.Windows.DependencyProperty CurrentReadingProperty =
            System.Windows.DependencyProperty.Register(
                "CurrentReading",
                typeof(MindwaveReading),
                typeof(MindwaveAttentionProgressBar),
                new System.Windows.PropertyMetadata(null));
        #endregion public MindwaveReading CurrentReading

    }
}
